The present invention pertains to the field of software optimization. More particularly, the present invention pertains to a method for optimizing Java software performance by optimizing code containing interface function calls to garbage collection.
Within the last five years there has arisen an ever increasing need to develop methods that allow a single computer program, written in one programming language, to run on various computer platforms or machines and/or operating systems that are either networked together or stand alone. For instance, the ability to run one program or application written in a single programming language on both an Apple(copyright) computer running a version of the Apple Operating System(copyright) and a personal computer (PC) running a version of the Microsoft(copyright) Windows(copyright) brand operating system. This xe2x80x9ccross-platformxe2x80x9d or xe2x80x9cportabilityxe2x80x9d need was acerbated by the commercialization of the World Wide Web and the advent of the Internet and the proliferation of Intranet networks. SUN Microsystems(copyright) released the JAVA programming language and its associated set of compilers as an answer to programmers"" and users"" portability needs.
The Java programming language is designed to be a machine-independent programming language. Java source code, as compared with C, C++, or FORTRAN, is compiled into a universal format, called bytecode. Bytecode is a set of instructions for a Virtual Machine (VM) instead of native instructions for a particular model of processor. Native code or native instructions are platform-dependent, i.e. tied to a particular model of processor. A Virtual Machine is software that mimics the performance of a hardware device. The Java bytecode is machine-independent code generated by the Java compiler and executed by the Java interpreter compiled at the last minute by a xe2x80x9cjust-in-timexe2x80x9d compiler (JIT) compiler. The Java bytecode resembles machine code but is not specific to any one model of processor.
However, there exist certain situations when a programmer or a developer or a user (hereinafter programmer) may desire to have an application or program written in both Java language and some other non-Java language like C or C++. The non-Java language is compiled into native code. This situation typically arises when a programmer wants to speed up the execution time of a program or application. Writing certain methods in a non-Java language may speed up execution time because these methods are compiled ahead of time and not at run time and as such have no JIT time and allow much more aggressive optimization techniques to be applied to them at compile time. A programmer can determine the time it takes each method in a program or application to run by profiling the program using any number of software tools and packages, such as Intel""s VTune(trademark) 4.0. A programmer can use the resultant profile information to determine which methods are slow to execute and then elect to rewrite these methods in native code, such as C or C++. To compile such mixed language or mixed mode code the programmer uses a mixed mode Java compiler such as Intel""s Bytecode Accelerator (described, e.g., in U.S. patent application Ser. No. 09/107,702, now U.S. Pat. No. 6,289,506 filed Jun. 30, 1998).
In a mixed mode environment calling from native code to Java code and vice versa, or from Java code to a Virtual Machine or vice versa, requires certain interface protocols so that the non-Java and Java methods or Java code and VM interact properly, which is required for a program""s ultimate functionality. For instance, if a programmer is working in Microsoft(copyright) Corporation""s Java environment the above interface is called the xe2x80x9craw native interfacexe2x80x9d (RNI). RNI acts as an interface to the Microsoft(copyright) Virtual Machine. However, writing a program in a mixed mode manner means that some of the benefits that the Java language offers the programmer such as Java garbage collection, can be lost. Garbage collection is an automatic system for allocating and freeing memory in Java. Microsoft(copyright), as well as the developers of other Virtual Machines, has developed methods to ensure that objects garbage-collected by the VM are processed correctly. When running on the Microsoft(copyright) Virtual Machine the mixed mode compiler needs to issue RNI function calls specifically designed to keep track of these garbage-collected objects. However, these RNI function calls can severely impact program execution performances.
The present invention introduces a method of optimizing program code performance. The method of the present invention analyzes a set of interface function calls from a native method to a Java Virtual Machine. Then selects a plurality of the set of interface function calls by analyzing a bytecode and/or an intermediate language for at least one of code constructs, including invocation of a native interface function call to perform garbage collection and then either eliminating or moving such inefficient code within the program.